package com.algorithm7;

import java.util.Arrays;

public class QuickSort1 {
    private static void quickSort(int[] array,int low,int height){
        if(low<height){
            int pivot = partion(array,low,height);
            quickSort(array,low,pivot-1);
            quickSort(array,pivot+1,height);
        }

    }

    private static int partion(int[] array,int p,int q){
        int piv = q;
        int i = p;
        for(int j=p;j<q;j++){
            if(array[j]<array[piv]){
                if(i!=j){
                    swap(array,j,i);
                }
                i++;
            }
        }
        swap(array,piv,i);

        return i;
    }

    private static void swap(int[] array,int i,int j){
        int temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }


    public static void main(String[] args){
        int[] array = {1,3,5,7,9,2,4,6,8,10};
        //int[] array = new int[]{4,3,5,8,9,7,10,6,1,2};
        quickSort(array,0,array.length-1);
        System.out.println(Arrays.toString(array));

    }
}
